// 认关路由配置

const Router = require('@koa/router');
const mongoose = require('mongoose');
const InventoryLogModel = mongoose.model('InventoryLog');

const router = new Router({
  prefix: '/inventory-log',
});

//
router.get('/list', async (ctx) => {
  console.log('--> 调用接口 get /inventory/list');
  console.log(ctx.query);
  let { type, size, page } = ctx.query;
  size = Number(size);
  page = Number(page);
  const list = await InventoryLogModel.find({ type })
    .sort({ _id: -1 })
    .skip((page - 1) * size)
    .limit(size)
    .exec();
  const total = await InventoryLogModel.find({ type }).countDocuments();
  ctx.body = {
    msg: '获取出入库日志成功',
    code: 1,
    data: {
      list,
      total,
      page,
      size,
    },
  };
});

module.exports = router;
